package com.ssy.lingxi.contract.model.constant;

import java.util.Arrays;

/**
 * 合同支付方式枚举
 * @author 伍将
 * @date 2021/2/7
 * @version 2.0.0
 */
public enum ContractPayWayEnum {


    PAYMENT_DAYS(1, "账期"),
    MONTH_SETTLEMENT(2, "月结"),
    CASH_SETTLEMENT(3, "现结");

    private final Integer code;
    private final String message;

    ContractPayWayEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public static String getMessage(Integer code, Integer param) {
        ContractPayWayEnum wayEnum = Arrays.stream(ContractPayWayEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        if(wayEnum==null){
            return "未知";
        }
        String result;
        switch (wayEnum) {
            case CASH_SETTLEMENT:
                result = wayEnum.getMessage();
                break;
            case PAYMENT_DAYS:
                result = (wayEnum.getMessage() + ":" + param + "天");
                break;
            case MONTH_SETTLEMENT:
                result = (wayEnum.getMessage() + ":每月" + param + "号请款");
                break;
            default:
                result = "";
                break;
        }

        return result;
    }

    public static ContractPayWayEnum find(Integer code) {
        return Arrays.stream(ContractPayWayEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
    }
}
